<%--
  @author  lk
  DateTime: 2020/4/14 0014 14:10
--%>
<%@ page import="com.lk.bean.CartItem" %>
<%@ page import="java.util.Map" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>购物车列表</title>
</head>
<body>
<table width=" 100%" align="center" border="1px">
    <tr>
        <th>商品编号</th>
        <th>商品名称</th>
        <th>商品单价</th>
        <th>商品数量</th>
        <th>商品小计</th>
        <th>操 作</th>
    </tr>
    <%
        // 1:将添加到购物车里面的物品显示出来
        Map<Integer, CartItem> map = (Map<Integer, CartItem>) session.getAttribute("cart");
        double count = 0;//显示出总价格
        if (map == null) {
            out.println("<strong >您现在购物车暂时为空</strong>");
            out.println("<br><strong >快去选购吧</strong ><br>");
        } else {
            // 2:将购物车里面的内容遍历出来
            for (Map.Entry<Integer, CartItem> entry : map.entrySet()) {
                //计算出每一样的商品一共花了多少钱
                double price = Double.parseDouble(entry.getValue().getGoods().getGoodsPrice()) * entry.getValue().getNumber();
                //计算出一共花了多少钱
                count = count + price;
    %>
    <tr align="center">
        <td><%=entry.getKey() %>
        </td>
        <td><%=entry.getValue().getGoods().getGoodsName() %>
        </td>
        <td><%=entry.getValue().getGoods().getGoodsPrice() %>
        </td>
        <td><%=entry.getValue().getNumber() %>
        </td>
        <td><%=Double.parseDouble(entry.getValue().getGoods().getGoodsPrice()) * entry.getValue().getNumber()%>
        </td>
        <td><a href="/deleteCart?id=<%=entry.getValue().getGoods().getGoodsId()%>">清除</a>
        </td>
    </tr>
    <%
            }
        }
    %>
    <tr>
        <td colspan="4 " align="center">价格总计</td>
        <td colspan="4 " align="center"><%=count %>
        </td>
    </tr>
</table>
<div style="text-align:center;font-size:  36px;">
    <a href="index.jsp">首页</a>
</div>
<div style="text-align:center;font-size:  30px;">
    <a href="pay.jsp">全部结算</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <a href="/deleteCart?id=-1">全部清空</a>
</div>
</body>
</html>
